package com.zoke.support.floatingmenu;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.zoke.support.R;
import com.zoke.support.base.BaseObjectListAdapter;
import com.zoke.support.floatingmenu.FloatingItem.FloatingItemType;
import com.zoke.support.utils.LogUtil;
import com.zoke.support.utils.ViewHolder;
import com.zoke.support.view.ZokeTextView;

/**
 * 漂浮窗口数据适配器
 * 
 * @author JackWu
 * @version
 * @date 2014-11-20
 * @_QQ_ 651319154
 */
public class FloatingAdapter extends BaseObjectListAdapter {

	public FloatingAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
	}

	@Override
	public View getItemView(int position, View convertView, ViewGroup parent) {
		convertView = getConvertView(convertView,
				R.layout.listview_item_floatingmenu);
		FloatingItem item = (FloatingItem) mDatas.get(position);
		LinearLayout mContainerLl = ViewHolder.get(convertView,
				R.id.item_container);
		ZokeTextView mItemTv = ViewHolder.get(convertView, R.id.item_name_tv);
		mItemTv.setText(item.getName());
		LogUtil.i("--------------------执行floating---------");
		// 父类选中 字体颜色改变/条目背景色改变
		// 子类选中 字体颜色改变/条目背景色不变
		if (item.isSelected()) {
			// 选中
			if (item.getType() == FloatingItemType._PARENT) {
				mContainerLl.setBackgroundResource(R.drawable.floating_item_bg);
			} else {
				mContainerLl.setBackgroundResource(R.drawable.floating_item_bg);
			}
			mItemTv.setTextColor(mContext.getResources().getColor(
					R.color._float_selected));
		} else {
			// 未选中
			if (item.getType() == FloatingItemType._PARENT) {
				mContainerLl.setBackgroundResource(R.drawable.zk_white);
			} else {
				mContainerLl.setBackgroundResource(R.drawable.floating_item_bg);
			}
			mItemTv.setTextColor(mContext.getResources().getColor(
					R.color._float_normal));
		}
		return convertView;
	}

}
